package actions;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.rowset.CachedRowSet;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import model.StudentDBModel;

public class ReviewStudent extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		
		StudentDBModel db = new StudentDBModel();
		
		String studentID = request.getParameter("studentID");

		request.setAttribute("studentID", studentID);
		
		CachedRowSet crsApp = db.getEntireAppByStudentID(studentID);
		CachedRowSet crsFeedback = db.getAppFeedback(studentID);
		Vector<String> entireApp = new Vector<String>();
		try{
			
			boolean first = true;
			while(crsApp.next())
			{
				if(first){
					
					
					entireApp.add("Application For:");
					entireApp.add(crsApp.getString("firstname") + " " + crsApp.getString("middleinitial") + " " + crsApp.getString("lastname"));
					entireApp.add("");
					entireApp.add("Specializing In " + db.getSpecNameById(crsApp.getInt("specialization")));
					entireApp.add("");
					entireApp.add("Citizen of: " + db.getCountryNameById(crsApp.getInt("citizenship")));
					entireApp.add("Resident of: " + db.getCountryNameById(crsApp.getInt("residence")));
					entireApp.add("");
					entireApp.add("Address:");
					entireApp.add(crsApp.getString("street"));
					entireApp.add(crsApp.getString("city"));
					entireApp.add(crsApp.getString("zipcode"));
					
					if(crsApp.getString("state") != null)
					{
						entireApp.add(crsApp.getString("state"));
					}
					else
					{
						entireApp.add(crsApp.getString("telephonecode"));
					}
					
					entireApp.add("(" + crsApp.getString("areacode") + ") "+ crsApp.getString("telephonenumber")+"\n");
					entireApp.add("");
					first = false;
				}
				
				entireApp.add("Degrees of "+crsApp.getString("firstname") + " " + crsApp.getString("middleinitial") + " " + crsApp.getString("lastname") + ":");
				entireApp.add("");
				entireApp.add("\nUniversity: " + db.getUniNameById(crsApp.getInt("university")));
				entireApp.add(db.getDiscNameById(crsApp.getInt("discipline")));
				entireApp.add("Date received: " + crsApp.getString("date"));
				entireApp.add("GPA: " + crsApp.getString("gpa"));
				entireApp.add("Level: " + crsApp.getString("type")+"\n");
				entireApp.add("");
			}
			
			first = true;
			
			while(crsFeedback.next())
			{
				if(first){
					entireApp.add("");
					entireApp.add("");
					entireApp.add("Other Reviewers Feedback:");
					entireApp.add("");
					first = false;
				}
				
				entireApp.add("As Reviewed By "+ crsFeedback.getString("reviewer_name")+":");
				entireApp.add("Score: "+ crsFeedback.getInt("score"));
				entireApp.add("Comment:");
				entireApp.add("\t"+crsFeedback.getString("comment"));
				entireApp.add("");
				
			}
			
			
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
		request.setAttribute("entireApp", entireApp);
		return mapping.findForward("success");
	}

}
